#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdlib.h>

static int a=100;

int main(int argc,char* const argv){

    // int a=0;
    int status=-1;
    pid_t pid=-1;
    pid = fork();
    if(pid < 0){
        perror("fork err");
        return -1;
    }else if(pid == 0){
        printf("in child\n");
        exit(42);
    }else{
        
        printf("in parent\n");
        if(wait(&status) == -1){
            perror("wait err");
            exit(EXIT_FAILURE);
        }
        if(WIFEXITED(status)){
            int exit_status =WEXITSTATUS(status);
            printf("exit status:%d\n",exit_status);
        }else if(WIFSIGNALED(status)){
            int term_sig = WTERMSIG(status);
            printf("sig : %d\n",term_sig);
        }else{
            printf("other\n");
        }
    }
    

    return 0;
}